﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


public class Engine : IGameCoordinator
{
    private List<Game> games;
    private static Engine engine;

    private Engine()
    {
        games = new List<Game>();
    }

    public static Engine GenerateEngine()
    {
        if (engine == null)
        {
            engine = new Engine();
        }
        return engine;
    }

    /// <summary>
    /// Adds a game or all games accordin to the passed paraeters.
    /// </summary>
    /// <param name="game">Idicates which game to add</param>
    /// <param name="diff">Specifies the difficulty of the games</param>
    public void ChooseGame(int game, int diff)
    {
        games.Clear();
        switch (game)
        {
            case 1:
                games.Add(new RockPaperLizard(diff));
                break;
            case 2:
                games.Add(new ReflexAssessment(diff));               
                break;
            case 3:
                games.Add(new MatrixCalculator(diff));                
                break;
            case 4:
                games.Add(new PairsGame(diff));
                break;
            case 5:
                games.Add(new ReflexAssessment(9));
                games.Add(new MatrixCalculator(9));
                games.Add(new RockPaperLizard(9));
                games.Add(new PairsGame(9));
                break;
        }
         
    }

    public void StartGameZ()
    {
        Player ultraPro = new Player("", 0);
        foreach (Game gg in games)
        {
            Console.Clear();
            gg.StartGame();
            ultraPro.Result = ultraPro.Result + gg.Result;
        }
        if (this.games.Count > 1)
        {
            this.PlayerToHOF(ultraPro);
        }
        
    }

    private void PlayerToHOF(Player ultraPro)
    {
        Console.Clear();
        HallOfFame hof = HallOfFame.GenerateHOF();
        Console.Write("Your total score is: " + ultraPro.Result);
        Console.WriteLine();
        Console.Write("Enter your name: ");
        string name = Console.ReadLine();
        ultraPro.Name = name;
        hof.AddPlayer(ultraPro);
        hof.Display();
    }

    
}

